using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace MTRC.ODMS.Web.SOM.AssetLoan
{
    /// <summary>
    /// author:Nearly
    /// </summary>
    public partial class AssetLoanEnquiry : BasePage_SOM
    {
        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140401";
            }
        }

        #endregion

        #region  Page Load and UnLoad

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grdAssetLoanEnquiry.PageSize = this.GridViewPageDefaultSize();

                InitializePage();
                SetLanguage();

                /*******************add by jack 20151202 for using session store enquiry condition satrt**********************/
                string isBack = Request.QueryString["isBack"];
                if (isBack == "1")
                {
                    this.ddlStation.SelectedValue = Session["Common_Station"].ToString();
                    this.dtbFromDate.Text = Session["Common_DateFrom"].ToString();
                    this.dtbToDate.Text = Session["Common_DateTo"].ToString();
                    this.SetCheckboxListValue(Session["Common_ShowList"].ToString(), this.chklShow);
                    this.cbxReturnItemOs.Checked = Convert.ToBoolean(Session["AssetLoan_ReturnItemOs"].ToString());
                    this.txtStaffID.Value = Session["AssetLoan_StaffID"].ToString();
                    this.txtStaffName.Value = Session["AssetLoan_StaffName"].ToString();
                    this.txtDepartmentCompany.Value = Session["AssetLoan_DepartmentCompany"].ToString();
                }
                /*******************add by jack 20151202 for using session store enquiry condition end**********************/
            }
        }

        private void InitializePage()
        {
            DateTime CurrentDateTimeTo = MTRC.ODMS.DAL.COM.Util.GetCurrentSystemTime();
            CurrentDateTimeTo = CurrentDateTimeTo.Date;
            this.dtbToDate.SetDateTime(CurrentDateTimeTo);
            string strDateRangel = DAL.CommonData.GetParameter("SOM_AssetLoanEnquiryDateRange").Rows[0]["ParamNumeric"].ToString();
            if (strDateRangel.Length > 0)
            {
                DateTime CurrentDateTimeFrom = new DateTime();
                try
                {
                    CurrentDateTimeFrom = CurrentDateTimeTo.AddDays(-(int.Parse(strDateRangel)));
                }
                catch
                {
                    CurrentDateTimeFrom = CurrentDateTimeTo.AddDays(0);
                }
                this.dtbFromDate.SetDateTime(CurrentDateTimeFrom);

            }

            if (DAL.Security.User.CanFunctionItemAccess("M140401_F1", this.ODMUser.UserProfileID, this.MenuID))
            {
                this.btnNew.Disabled = true;
            }
            else
            {
                this.btnNew.Disabled = false;
            }
            if (Request.QueryString["isBack"] != null && Request.QueryString["isBack"].Trim() != string.Empty && Convert.ToInt32(Request.QueryString["isBack"].ToString()) > 0)
            {
                this.btnExporttoExcel.Disabled = false;
            }
            else
            {
                this.btnExporttoExcel.Disabled = true;
            }

            if (DAL.Security.User.CanFunctionItemAccess("M140401_F2", this.ODMUser.UserProfileID, this.MenuID))//access all station.
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), this.ODMUser.StationID), true);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, true, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true);
            }
            else if (DAL.Security.User.CanFunctionItemAccess("M140401_F3", this.ODMUser.UserProfileID, this.MenuID))//Can Access other stations.
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.StationID), true);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.LocationID), true);
            }
            else
            {
                //update by gordon 20151020 U247
                //BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.StationID), false);
                BindListControl(this.ddlStation, "LocationID", "station", DAL.SOM.CodeSetup.CDAssetType.AccessStationWithUserID(this.ODMUser.ID, false, Convert.ToInt16(LangCode), this.ODMUser.LocationID), false);
                this.ddlStation.Enabled = false;
            }

            //update by gordon 20151020 U247
            //this.FindByValueAndSelect(ddlStation, this.ODMUser.StationID.ToString());
            this.FindByValueAndSelect(ddlStation, this.ODMUser.LocationID.ToString());
        }

        private void SetLanguage()
        {
            this.lblFrom.Text = this.GetLabel("COM_From", true);
            this.lblTo.Text = this.GetLabel("COM_To", true);
            this.lblShow.Text = this.GetLabel("COM_Show", true);
            BindListControl(chklShow, "EventStatusID", "Description", DAL.SOM.CodeSetup.CDEventStatus.GetActive(this.LangCode), false);
            int intShowCount = this.chklShow.Items.Count;
            for (int i = 0; i < intShowCount; i++)
            {
                if (this.chklShow.Items[i].Value == "1")
                {
                    this.chklShow.Items[i].Selected = true;
                }
            }
            if (intShowCount > 0)
            {
                this.chklShow.Items.Insert(intShowCount - 1, this.GetLabel("SOM_Handover"));
                this.chklShow.Items[intShowCount - 1].Selected = true;

                //this.chklShow.Items.Insert(intShowCount + 1, this.GetLabel("SOM_ReturnedItemOfOSEvent"));
                //this.chklShow.Items[intShowCount + 1].Selected = false;
            }
            else
            {
                this.chklShow.Items.Insert(0, this.GetLabel("SOM_Handover"));
                this.chklShow.Items[0].Selected = true;
            }
            this.cbxReturnItemOs.Text = this.GetLabel("SOM_ReturnedItemOfOSEvent", false);
            this.lblStaffID.Text = this.GetLabel("SOM_BorrowerID", true);
            this.lblStaffName.Text = this.GetLabel("SOM_BorrowerName", true);
            this.lblStation.Text = this.GetLabel("SOM_Station", true);
            this.lblDepartmentCompany.Text = this.GetLabel("SOM_DepartmentCompany", true);
            this.btnNew.Value = this.GetLabel("SOM_AddNewAssetLoanItem");
            this.btnSearch.Value = this.GetLabel("COM_Search");
            this.btnExporttoExcel.Value = this.GetLabel("COM_Export");

            //added by Nathan 2015-08-15
            if (Request.QueryString["isBack"] != null && Request.QueryString["isBack"].Trim() != string.Empty && Convert.ToInt32(Request.QueryString["isBack"].ToString()) > 0)
            { }
            else
            {
                BindData();
            }
            //added by Nathan 2015-08-15
        }

        private void ChangeLanguage_Click(object sender, System.EventArgs e)
        {
            if (IsPostBack) //added by huangyao 20090120
            {
                InitializePage();
            }
            SetLanguage();
            if (this.hdnBoolClkBtn.Value == "YES")
            {
                BindData();
            }
        }

        #endregion

        #region Click Event

        private void btnNew_ServerClick(object sender, EventArgs e)
        {
            Response.Redirect(Request.ApplicationPath + "/SOM/AssetLoan/AssetLoanEntry.aspx?Action=NEW");
        }

        protected void btnSearch_ServerClick(object sender, EventArgs e)
        {
            try
            {
                if (dtbFromDate.Text.Trim().Length > 0 && dtbToDate.Text.Trim().Length > 0)
                {
                    if (InvalidateInputDate(this.dtbFromDate.GetDateTime(), this.dtbToDate.GetDateTime()))
                    {
                        PAlert(this.GetMessage("COM_StartEndDate"));
                        return;
                    }
                }
                this.hdnBoolClkBtn.Value = "YES";
                BindData();
            }
            finally
            {
                //add by gordon 20150812 | For Search Wait Cursor
                ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "", "showWait('');", true);
            }
        }

        private void btnExporttoExcel_ServerClick(object sender, EventArgs e)
        {
            //edit by hjh 20120516 for issue 1531
            //if (this.hdnCacheDataReturnInt.Value != "0")
            //{
            //    DataSet dsReturn = BLL.SOM.TempData.GetCacheData(int.Parse(this.hdnCacheDataReturnInt.Value));
            if (dtbFromDate.Text.Trim().Length > 0 && dtbToDate.Text.Trim().Length > 0)
            {
                if (InvalidateInputDate(this.dtbFromDate.GetDateTime(), this.dtbToDate.GetDateTime()))
                {
                    Alert(this.GetMessage("COM_StartEndDate"));
                    return;
                }
            }
            string stationIDs = "";
            SetStationSelectedItem(ref stationIDs, this.ddlStation);
            DataSet dsReturn = GetSearchResult(stationIDs);
            object limitExpCount = DAL.CommonData.GetNumVal("SOM_AssetLoanExportMAXControl");
            if (dsReturn == null)
            {
                return;
            }
            else if (limitExpCount != null && dsReturn.Tables[0].Rows.Count > int.Parse(limitExpCount.ToString()))//edit by hjh 20120516 for issue 1531
            {
                Alert(string.Format(this.GetMessage("SOM_ExportLimitControl"), int.Parse(limitExpCount.ToString())));
                return;
            }
            DataSet dsCopyReturn = new DataSet();
            dsCopyReturn = dsReturn.Copy();
            dsReturn.Dispose();
            dsReturn = null;
            DataTable dtSearchResult = new DataTable();
            dtSearchResult = dsCopyReturn.Tables[0];

            dtSearchResult.Columns.Remove("StationEventID");
            dtSearchResult.Columns.Remove("HandoverNote");
            dtSearchResult.Columns.Remove("StationEventAdmRegID");
            dtSearchResult.Columns.Remove("EventStatusID");
            /******************* modifidy by dylan 20150727 for u133 start**********************************/
            //dtSearchResult.Columns[0].ColumnName = this.GetLabel("SOM_EventNo");
            //dtSearchResult.Columns[1].ColumnName = this.GetLabel("SOM_DepartmentCompany");
            //dtSearchResult.Columns[2].ColumnName = this.GetLabel("SOM_AssetType");
            //dtSearchResult.Columns[3].ColumnName = this.GetLabel("SOM_AssetItem");
            //dtSearchResult.Columns[4].ColumnName = this.GetLabel("SOM_LoanQuantity");
            //dtSearchResult.Columns[5].ColumnName = this.GetLabel("SOM_ReturnQuantity");
            //dtSearchResult.Columns[6].ColumnName = this.GetLabel("SOM_BorrowerName");
            //dtSearchResult.Columns[7].ColumnName = this.GetLabel("SOM_BorrowDateTime");
            //dtSearchResult.Columns[8].ColumnName = this.GetLabel("SOM_ReturnDateTime");
            //dtSearchResult.Columns[9].ColumnName = this.GetLabel("COM_Status");
            //dtSearchResult.Columns[10].ColumnName = this.GetLabel("SOM_Handover");
            dtSearchResult.Columns["EventNo"].ColumnName = this.GetLabel("SOM_EventNo");
            dtSearchResult.Columns["DepartmentCompany"].ColumnName = this.GetLabel("SOM_DepartmentCompany");
            dtSearchResult.Columns["AssetTypeDesc"].ColumnName = this.GetLabel("SOM_AssetType");
            dtSearchResult.Columns["AssetItemDesc"].ColumnName = this.GetLabel("SOM_AssetItem");
            dtSearchResult.Columns["NumOfLoanItem"].ColumnName = this.GetLabel("SOM_LoanQuantity");
            dtSearchResult.Columns["NumOfReturnItem"].ColumnName = this.GetLabel("SOM_ReturnQuantity");
            dtSearchResult.Columns["StaffName"].ColumnName = this.GetLabel("SOM_BorrowerName");
            dtSearchResult.Columns["LoanTime"].ColumnName = this.GetLabel("SOM_BorrowDateTime");
            dtSearchResult.Columns["ReturnTime"].ColumnName = this.GetLabel("SOM_ReturnDateTime");

            /******************* add by dylan 20150727 for u133 start**********************************/
            dtSearchResult.Columns["Remark"].ColumnName = this.GetLabel("COM_Remark");

            /******************* add by dylan 20150727 for u133 end**********************************/

            dtSearchResult.Columns["EventStatusDesc"].ColumnName = this.GetLabel("COM_Status");
            dtSearchResult.Columns["FlagHandover"].ColumnName = this.GetLabel("SOM_Handover");
            /******************* modifidy by dylan 20150727 for u133 end**********************************/
            dtSearchResult.Columns.Add();
            for (int i = 0; i < dtSearchResult.Rows.Count; i++)
            {
                /******************* modifidy by dylan 20150727 for u133 start**********************************/
                if (dtSearchResult.Rows[i]["HighLight"].ToString() == "1")
                {
                    //dtSearchResult.Rows[i][12] = GetLabel("SOM_HighLightYellow");
                    dtSearchResult.Rows[i][14] = GetLabel("SOM_HighLightYellow");
                }
                else if (dtSearchResult.Rows[i]["HighLight"].ToString() == "2")
                {
                    //dtSearchResult.Rows[i][12] = GetLabel("SOM_HighLightRed");
                    dtSearchResult.Rows[i][14] = GetLabel("SOM_HighLightRed");
                }
                else
                {
                    //dtSearchResult.Rows[i][12] = GetLabel("SOM_HighLightNormal");
                    dtSearchResult.Rows[i][14] = GetLabel("SOM_HighLightNormal");
                }
                /******************* modifidy by dylan 20150727 for u133 end**********************************/
            }
            dtSearchResult.Columns.Remove("HighLight");
            // modifidy by dylan 20150727 for u133
            //dtSearchResult.Columns[11].ColumnName = this.GetLabel("SOM_HighLight");
            dtSearchResult.Columns[13].ColumnName = this.GetLabel("SOM_HighLight");

            /******************* add by dylan 20150727 for u133 start**********************************/
            dtSearchResult.Columns[this.GetLabel("COM_Remark")].SetOrdinal(13);
            dtSearchResult.Columns.Remove("ParentStationEventID");
            //Common.ExportExcel_showHHMM(dsCopyReturn, Context, "AssetLoanEnquiry.xls");
            //string templateFile = Server.MapPath("~") + string.Format(@"\Template\MTRC\AssetLoanEnquiry Template.xlsx");
            string templateFilePath = APJ.Util.Utility.GetAppSetting("SOM_ExportExcelTemplatePath");
            if (templateFilePath.LastIndexOf("\\") != templateFilePath.Length - 1)
                templateFilePath += "\\";
            string templateFile = templateFilePath + string.Format("AssetLoanEnquiry Template.xlsx");
            //string exportFile = Server.MapPath("~") + string.Format(@"\Template\MTRC\AssetLoanEnquiry.xlsx");
            string ExcelDownloadFilePath = APJ.Util.Utility.GetAppSetting("SOM_ExportExcelTempFilePath");
            if (ExcelDownloadFilePath.LastIndexOf("\\") != ExcelDownloadFilePath.Length - 1)
                ExcelDownloadFilePath += "\\";
            string exportFile = ExcelDownloadFilePath + string.Format("AssetLoanEnquiry" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");//add by jack 20160127 ISU22 fixed for same export file name
            //update by gordon 20150910
            //CreateExcelFile.ExportExcelWithTemplate(dtSearchResult, templateFile, exportFile, Response);
            CreateExcelFile.ExportExcelWithTemplate(dtSearchResult, templateFile, exportFile, Response, Page);
            /******************* add by dylan 20150727 for u133 end**********************************/
            dtSearchResult.Dispose();
            dtSearchResult = null;
            dsCopyReturn.Dispose();
            dsCopyReturn = null;
            //}
        }

        #endregion

        #region Data Grid Bind

        private DataSet GetSearchResult(string stationIDs)
        {
            bool StatusCom = false;
            bool StatusOS = false;
            bool StatusHandover = false;
            bool StatusVoid = false;
            /*StatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48  */
            bool StatusReturnedItemInOsEvent = false;
            /*StatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48  */
            StatusReturnedItemInOsEvent = this.cbxReturnItemOs.Checked;
            for (int i = 0; i < this.chklShow.Items.Count; i++)
            {
                if (this.chklShow.Items[i].Selected)
                {
                    if (this.chklShow.Items[i].Value == "2")
                    {
                        StatusCom = true;
                    }
                    else if (this.chklShow.Items[i].Value == "1")
                    {
                        StatusOS = true;
                    }
                    else if (this.chklShow.Items[i].Value == "3")
                    {
                        StatusVoid = true;
                    }
                    else if (this.chklShow.Items[i].Value == "Handover")
                    {
                        StatusHandover = true;
                    }
                    else
                    {
                        //StatusReturnedItemInOsEvent = true;
                    }

                }
            }

            DataSet dsEnquiry = MTRC.ODMS.BLL.SOM.Event.StationEventAssetLoan.GetAssetLoanEnquiry(this.LangCode,
                                                                                              this.ODMUser.LocationID, stationIDs,
                                                                                              this.dtbFromDate.GetDateTime(),
                                                                                              this.dtbToDate.GetDateTime(),
                                                                                              StatusCom, StatusOS, StatusHandover, StatusVoid, StatusReturnedItemInOsEvent,   /*StatusReturnedItemInOsEvent Add by Dylan 20150617 for ISSUE U48 */
                                                                                              this.txtStaffID.Value,
                                                                                              this.txtStaffName.Value,
                                                                                              this.txtDepartmentCompany.Value);
            //edit by hjh 20120516 for issue 1531
            //this.hdnCacheDataReturnInt.Value = BLL.SOM.TempData.CacheDataSet(dsEnquiry, this.ODMUser.ID, this.ODMUser.Domain.ToString()).ToString();
            return dsEnquiry;
        }
        private void BindData()
        {
            /* Comment by jack 20150822 for u70 */
            if (DAL.Security.User.CanFunctionItemAccess("M140401_F2", this.ODMUser.UserProfileID, this.MenuID))//access all station.
            {

            }
            else if (DAL.Security.User.CanFunctionItemAccess("M140401_F3", this.ODMUser.UserProfileID, this.MenuID))//Can Access other stations.
            {

            }
            else
            {
                if (!IsValidStation(this.ODMUser.LocationID))
                {

                    if (Request.QueryString["IsReject"] != "1")
                    {
                        this.PAlert(this.GetMessage("SOM_NotValidStation"));
                    }
                    this.ddlStation.Items.Clear();
                    DataTable dtNull = new DataTable();
                    this.grdAssetLoanEnquiry.DataSource = dtNull.DefaultView;
                    this.grdAssetLoanEnquiry.GetLabelFunction = new APJ.Web.UI.WebControls.GetLabel(this.GetLabel);
                    this.grdAssetLoanEnquiry.DataBind();
                    dtNull.Dispose();
                    return;
                }

            }
            /************************************/
            string stationIDs = "";
            SetStationSelectedItem(ref stationIDs, this.ddlStation);
            DataTable dtSearchResult = GetSearchResult(stationIDs).Tables[0];
            if (dtSearchResult.Rows.Count > 0)
            {
                this.btnExporttoExcel.Disabled = false;
            }
            else
            {
                this.btnExporttoExcel.Disabled = true;
            }
            this.grdAssetLoanEnquiry.GetLabelFunction = new APJ.Web.UI.WebControls.GetLabel(this.GetLabel);
            this.grdAssetLoanEnquiry.DataSource = dtSearchResult.DefaultView;
            this.grdAssetLoanEnquiry.DataBind();
            dtSearchResult.Dispose();
            dtSearchResult = null;
        }

        private void grdAssetLoanEnquiry_NeedDataBind()
        {
            BindData();
        }

        protected void grdAssetLoanEnquiry_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
            {
                //System.Web.UI.WebControls.HyperLink hl_LostCaseNo = new System.Web.UI.WebControls.HyperLink();
                //hl_LostCaseNo.Text = e.Row.Cells[0].Text;
                //hl_LostCaseNo.Target = "_blank";
                //hl_LostCaseNo.NavigateUrl = APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/AssetLoan/AssetLoanEntry.aspx?StationEventID=" + this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex][0].ToString();
                //e.Row.Cells[0].Controls.Clear();
                //e.Row.Cells[0].Controls.Add(hl_LostCaseNo);

                ////huangyao 20081129 in MTR office
                string urlString = APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/AssetLoan/AssetLoanEntry.aspx?StationEventID=" + this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex]["StationEventID"].ToString();
                string strScript = "OpenEntryPageMaximum('" + urlString + "');";
                //((HyperLink)e.Row.Cells[0].FindControl("hypLinkEventNo")).NavigateUrl = APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/AssetLoan/AssetLoanEntry.aspx?StationEventID=" + this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex][0].ToString();
                ((HyperLink)e.Row.Cells[0].FindControl("hypLinkEventNo")).NavigateUrl = "";
                ((HyperLink)e.Row.Cells[0].FindControl("hypLinkEventNo")).Font.Bold = true;
                ((HyperLink)e.Row.Cells[0].FindControl("hypLinkEventNo")).Target = "_blank";
                ((HyperLink)e.Row.Cells[0].FindControl("hypLinkEventNo")).Attributes.Add("onclick", strScript);
                if (((DataBoundLiteralControl)e.Row.Cells[13].Controls[0]).Text.Replace("\r\n", "").Trim().Length > 0)
                {
                    ((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).ImageUrl = Request.ApplicationPath + "/Images/SOM/Admission_Registry_Link.gif";
                    //huangyao 20081129 in MTR office
                    string urlString2 = APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/AdmissionRegistry/AdmissionRegistryEntry.aspx?StationEventID=" + this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex]["ParentStationEventID"].ToString();//update by benson 2015-08-19: this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex]["StationEventAdmRegID"]  to   this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex]["ParentStationEventID"]
                    string strScript2 = "OpenEntryPageMaximum('" + urlString2 + "');";
                    //((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).NavigateUrl = APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/AdmissionRegistry/AdmissionRegistryEntry.aspx?StationEventID=" + this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex]["StationEventAdmRegID"].ToString();
                    ((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).NavigateUrl = "";
                    ((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).Font.Bold = true;
                    ((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).Target = "_blank";
                    ((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).Attributes.Add("onclick", strScript2);
                    //----------------------
                    ((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).ToolTip = this.GetLabel("SOM_AdmissionRegistryLink");
                }
                else
                {
                    ((HyperLink)e.Row.Cells[0].FindControl("hypLinkAdminReg")).ImageUrl = Request.ApplicationPath + "/Images/spacer.gif";
                }

                if (((DataBoundLiteralControl)e.Row.Cells[7].Controls[0]).Text.Contains("1"))
                {
                    ((Image)e.Row.Cells[8].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/EventStatus_OS.gif";
                    ((Image)e.Row.Cells[8].Controls[1]).ToolTip = this.GetLabel("SOM_OS", false);
                }
                else if (((DataBoundLiteralControl)e.Row.Cells[7].Controls[0]).Text.Contains("2"))
                {
                    ((Image)e.Row.Cells[8].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/EventStatus_COM.gif";
                    ((Image)e.Row.Cells[8].Controls[1]).ToolTip = this.GetLabel("SOM_Completed", false);
                }
                else
                {
                    ((Image)e.Row.Cells[8].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/EventStatus_Void.gif";
                    ((Image)e.Row.Cells[8].Controls[1]).ToolTip = this.GetLabel("SOM_Void", false);
                }

                if (((DataBoundLiteralControl)e.Row.Cells[9].Controls[0]).Text.Contains("True"))
                {
                    ((Image)e.Row.Cells[10].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/EventHandOver.gif";
                    ((Image)e.Row.Cells[10].Controls[1]).ToolTip = ((Label)e.Row.Cells[14].FindControl("lblHandoverNote")).Text.Trim().Replace("\r\n", "");
                }
                else
                {
                    // edit by dylan 20150820 for u81.1
                    string HandOverNote = ((Label)e.Row.Cells[14].FindControl("lblHandoverNote")).Text;
                    if (!string.IsNullOrEmpty(HandOverNote))
                    {
                        ((Image)e.Row.Cells[10].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/EventHandOverDone.jpg";
                        ((Image)e.Row.Cells[10].Controls[1]).ToolTip = HandOverNote.Replace("\r\n", "");
                    }
                    else
                    {
                        ((Image)e.Row.Cells[10].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/spacer.gif";
                    }
                }
                //update by benson 2015.08.27 u183.3 begin
                if (((DataBoundLiteralControl)e.Row.Cells[7].Controls[0]).Text.Contains("2"))
                {
                    ((Image)e.Row.Cells[12].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/HighLight_Normal.gif";
                    ((Image)e.Row.Cells[12].Controls[1]).ToolTip = GetLabel("SOM_HighLightNormal");
                }
                //update by benson 2015.08.27 u183.3 end
                else if (((DataBoundLiteralControl)e.Row.Cells[11].Controls[0]).Text.Contains("1"))
                {
                    ((Image)e.Row.Cells[12].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/HighLight_Yellow.gif";
                    ((Image)e.Row.Cells[12].Controls[1]).ToolTip = GetLabel("SOM_HighLightYellow");
                }
                else if (((DataBoundLiteralControl)e.Row.Cells[11].Controls[0]).Text.Contains("2"))
                {
                    ((Image)e.Row.Cells[12].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/HighLight_Red.gif";
                    ((Image)e.Row.Cells[12].Controls[1]).ToolTip = GetLabel("SOM_HighLightRed");
                }
                else
                {
                    ((Image)e.Row.Cells[12].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/SOM/HighLight_Normal.gif";
                    ((Image)e.Row.Cells[12].Controls[1]).ToolTip = GetLabel("SOM_HighLightNormal");
                }

                //if (((DataBoundLiteralControl)e.Row.Cells[16].Controls[0]).Text.Replace("\r\n", "").Trim().Length > 0)
                //{
                //    ((HyperLink)e.Row.Cells[1].FindControl("hlAdmissionRegistryLink")).ImageUrl = Request.ApplicationPath + "/Images/SOM/Admission_Registry_Link.gif";
                //    ((HyperLink)e.Row.Cells[1].FindControl("hlAdmissionRegistryLink")).NavigateUrl = APJ.Util.Utility.GetHttpHost(this.Request) + "/SOM/AdmissionRegistry/AdmissionRegistryEntry.aspx?StationEventID=" + this.grdAssetLoanEnquiry.DataKeys[e.Row.RowIndex][0].ToString();
                //    ((HyperLink)e.Row.Cells[1].FindControl("hlAdmissionRegistryLink")).Target = "_blank";
                //    ((HyperLink)e.Row.Cells[1].FindControl("hlAdmissionRegistryLink")).ToolTip = this.GetLabel("SOM_AdmissionRegistryLink");
                //}
                //else
                //{
                //((HyperLink)e.Row.Cells[1].Controls[1]).ImageUrl = Request.ApplicationPath + "/Images/spacer.gif";
                //}

                //Add by LiangZehong on 2008-12-17 Begin...
                Label lblLoanReturnQuantity = e.Row.FindControl("lblLoanReturnQuantity") as Label;
                if (lblLoanReturnQuantity != null)
                {
                    lblLoanReturnQuantity.Text = string.Format("{0}/{1}", DataBinder.Eval(e.Row.DataItem, "NumOfLoanItem").ToString(), DataBinder.Eval(e.Row.DataItem, "NumOfReturnItem").ToString());
                }
                Label lblBorrowReturnDateTime = e.Row.FindControl("lblBorrowReturnDateTime") as Label;
                if (lblBorrowReturnDateTime != null)
                {
                    string LoanTime = string.Empty;
                    string ReturnTime = string.Empty;
                    LoanTime = this.FormatDateTime(DataBinder.Eval(e.Row.DataItem, "LoanTime").ToString(), true);
                    ReturnTime = this.FormatDateTime(DataBinder.Eval(e.Row.DataItem, "ReturnTime").ToString(), true);
                    ReturnTime = string.IsNullOrEmpty(ReturnTime) ? this.GetLabel("SOM_UnReturned") : ReturnTime; // if Return Time is empty, then display "Un Returned"

                    lblBorrowReturnDateTime.Text = string.Format("{0}<br />{1}", LoanTime, ReturnTime);
                }
                //End...
            }
        }

        #endregion

        #region Web Form Designer generated code

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.ChangeLanguage += new MTRC.ODMS.Web.BasePage.ChangeLanguageEventHandler(this.ChangeLanguage_Click);
            this.btnSearch.ServerClick += new EventHandler(btnSearch_ServerClick);
            this.btnExporttoExcel.ServerClick += new EventHandler(btnExporttoExcel_ServerClick);
            this.btnNew.ServerClick += new EventHandler(btnNew_ServerClick);
            this.grdAssetLoanEnquiry.NeedDataBind += new APJ.Web.UI.WebControls.CommonGridView.NeedDataBindHandler(grdAssetLoanEnquiry_NeedDataBind);
        }


        #endregion

        /// <summary>
        ///  add by jack 20151202 for using session store enquiry condition
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSetSession_Click(object sender, EventArgs e)
        {
            this.RemoveCommonSession();

            string Url = this.HiddenFieldUrl.Value;
            Session["Common_Station"] = this.ddlStation.SelectedValue.ToString();
            Session["Common_DateFrom"] = this.dtbFromDate.Text.ToString();
            Session["Common_DateTo"] = this.dtbToDate.Text.ToString();
            string ShowList = this.GetCheckboxListValue(this.chklShow);
            Session["Common_ShowList"] = ShowList.ToString();
            Session["AssetLoan_StaffID"] = this.txtStaffID.Value.ToString();
            Session["AssetLoan_StaffName"] = this.txtStaffName.Value.ToString();
            Session["AssetLoan_ReturnItemOs"] = this.cbxReturnItemOs.Checked;
            Session["AssetLoan_DepartmentCompany"] = this.txtDepartmentCompany.Value.ToString();
            Response.Redirect(Url + "&isBack=1&PageID=AssetLoanEnquiry");
        }
    }
}